package cn.hackcloud.concurrency.activeobject;

import cn.hackcloud.concurrency.activeobjects.ActiveMethod;
import cn.hackcloud.concurrency.future.Future;
import cn.hackcloud.concurrency.future.FutureService;

import java.util.concurrent.TimeUnit;

public class OrderServiceImpl implements OrderService {
    @Override
    @ActiveMethod
    public Future<String> findOrderDetails(long orderId) {
        return FutureService.<Long, String>newService().submit(input -> {
            try {
                TimeUnit.SECONDS.sleep(3);
                System.out.println("process the orderId->" + orderId);
            } catch (Exception e) {
                e.printStackTrace();

            }
            return "the order Details information";
        }, orderId, null);
    }

    @Override
    @ActiveMethod
    public void order(String account, long orderId) {
        try {
            TimeUnit.SECONDS.sleep(3);
            System.out.println("process the order for account " + account + " orderId->" + orderId);
        } catch (Exception e) {
            e.printStackTrace();

        }
    }
}
